<?php
/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2016/8/11
 * Time: 14:01
 */
namespace YMApi\Model;
use Think\Model;

class EvaluateModel extends Model
{
    protected $tableName = 'comment';
    
    /**
     * 获取商品评价列表
     * @param unknown $goods_id
     * @param number $limit
     */
    public function get_goods_evaluate($goods_id,$limit=0){

        
        $comment_goods = M('comment_goods')->alias('a')->join("left join ".C('DB_PREFIX')."comment b on a.comment_id=b.comment_id")->where(array('a.goods_id'=>$goods_id,'b.status'=>'1'))->order("b.add_time desc")->field('*,a.comment_rank as comment_rank')->limit($limit)->select();
        
        $comment_goods_count = M('comment_goods')->alias('a')->join("left join ".C('DB_PREFIX')."comment b on a.comment_id=b.comment_id")->where(array('a.goods_id'=>$goods_id,'b.status'=>'1'))->order("b.add_time desc")->field('*,a.comment_rank as comment_rank')->count();
        
        $comment_list_a['count']=$comment_goods_count;
        
        $comment_list=array();
        foreach($comment_goods as $li){
            $comment=array();
            $wechat_user = M("wechat_user")->field("headimgurl")->where(array("ect_uid"=>$li['user_id']))->find();
            $comment['user_name']=$li['user_name'];
            $comment['comment_rank']=$li['comment_rank'];
            $comment['content']=$li['content'];
            $comment['add_time']=local_date('m月d日 H:i:s',$li['add_time']);
            $comment['headImage']=str_replace("http://", "https://", $wechat_user['headimgurl']);
            $comment_list[]=$comment;
        }
        $comment_list_a['goods']=$comment_list;
        return $comment_list_a;
         
    }
    
    
    
    
    
}